package com.lianliang.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lianliang.dao.LoginLogDao;
import com.lianliang.dao.UserDao;
import com.lianliang.domain.LoginLog;
import com.lianliang.domain.User;


@Service
public class UserService {
	
	@Autowired
	private UserDao userDao;
	@Autowired
	private LoginLogDao loginLogDao;
	
	public Boolean hasMatchUsesr(String userName,String password){
		Integer count = userDao.getMatchCount(userName, password);
		return count>0;
	}
	
	public User findUserByUserName(String userName){
		return userDao.findUserByUserName(userName);
	}
	
	public void loginSuccess(User user){
		user.setCredits(5+user.getCredits());
		LoginLog log = new LoginLog();
		log.setUserId(user.getUserId());
		log.setIp(user.getLastIp());
		log.setLoginDate(user.getLastVisit());
		userDao.updateLoginLog(user);
		loginLogDao.insertLoginLog(log);
	}
	
}
